package Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

/*
    Collections中常用方法的分类:
    1.转换成不可变集合的类别
    2.同步安全类
    3.查找替换类
    4.排序类
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        ArrayList arrayList=new ArrayList<>();
        //添加元素
        Collections.addAll(arrayList,5,2,7,4);
        System.out.println(arrayList);
        //排序
        Collections.sort(arrayList);
        System.out.println(arrayList);
        //二分查找,查找前必须排序
        System.out.println(Collections.binarySearch(arrayList,4));
        //判断两个集合有没有共同元素，有返回false，没有返回true
        ArrayList arrayList1=new ArrayList<>();
        Collections.addAll(arrayList1,9,1,6,8);
        System.out.println(Collections.disjoint(arrayList,arrayList1));
        Collection collection=Collections.unmodifiableCollection(arrayList);
//        Collections.addAll(collection,1,2);
        System.out.println(collection);
        //将指定集合乱序
//        Collections.shuffle(arrayList1);
//        System.out.println(arrayList1);
        //返回只包含一个元素的不可变的list
        System.out.println(Collections.singleton(1));
        //返回指定列表中目标列表第一次出现的位置，没有返回-1
        System.out.println(Collections.indexOfSubList(arrayList1,Collections.singletonList(1)));
    }
}
